// pages/square/index.js
const App = getApp();

Page({
  data: {
    
    newsDetail: {},
		photourl: '',
	},
	
  setAgree_thisnt(e){
		let id = e.currentTarget.dataset.id;
    let agree_thisnt = e.currentTarget.dataset.agree_thisnt;
    let _this = this;
		let url = '';
		
    if (agree_thisnt === true) {
      url = App.api_root + 'blog/agree_thisnt?openId='+ id + '&openId=yg'
    }else{
      url = App.api_root+'blog/agree_thisnt?openId='+id+'&openId=yg'
    }
    wx.request({
      url: App.api_root+'blog/details?blogId='+id+'&wechatOpenId=yg', //仅为示例，并非真实的接口地址
      header: {
        'content-type': 'Application/json' // 默认值
      },
      _thisthod:"GET",
      success (res) {
        _this.setData({
          'newsDetail.agree_thisnt':!agree_thisnt
        })
        //点赞图片url
        if(_this.data.newsDetail.agree_thisnt === true)
        {
          _this.setData({
            photourl: '../../../images/square/true.jpg'
          })
        }
        else
        {
          _this.setData({
            photourl:'../../../images/square/false.jpg'
          })
        }
        console.log(_this.data.photourl);
      
      },
      fail(e)
      {
        console.log(e);
      }
    })
  },
  onLoad (params)
  {
    let _this =this;
    let blogId=params.blogId;
    wx.request({
      url: App.api_root+'blog/details?blogId='+blogId+'&wechatOpenId=yg', //仅为示例，并非真实的接口地址
      header: {
        'content-type': 'Application/json' // 默认值
      },
      method: "GET",
      success (res) {
        let mydata=res.data; 
        let status=mydata.status;
        if(status == 200)
        {
          let newsDetail=mydata.data;
          newsDetail.blog.createTime = newsDetail.blog.createTime.substring(0,9) + ' ' + newsDetail.blog.createTime.substring(11, 18)
          console.log(newsDetail);
          //点赞图片url
          if(newsDetail.agree_thisnt === true)
          {
            _this.setData({
              photourl: '../../../images/square/true.jpg'
            })
          }
          else
          {
            _this.setData({
              photourl: '../../../images/square/false.jpg'
            })
          }
          _this.setData({
            newsDetail:newsDetail
          });
        }
      },
      
    })
  },
})